<template>
  <el-breadcrumb separator="/" class="mb-2 mt-1" style="vertical-align: bottom">
    <el-breadcrumb-item>
      <div class="flex align-center">
        <el-icon :size="18"><Setting /></el-icon>
        <span class="pl">设定</span>
      </div>
    </el-breadcrumb-item>
    <el-breadcrumb-item>默認回復設定</el-breadcrumb-item>
    <el-breadcrumb-item>消息内容</el-breadcrumb-item>
  </el-breadcrumb>
  <el-card class="box-card" shadow="hover">
    <el-tabs v-model="params.material_type" class="demo-tabs" @tab-click="handleClick">
      <el-tab-pane label="文字區塊" name="text"> </el-tab-pane>
      <el-tab-pane label="圖文組合區塊" name="news"> </el-tab-pane>
    </el-tabs>
    <div class="flex justify-between flex-wrap mb-2">
      <el-space wrap :size="10" class="mt-1">
        <el-input
          v-model="params.material_name"
          style="width: 150px"
          placeholder="素材名稱"
        />
        <el-button :icon="Search" plain @click="search">查詢</el-button>
      </el-space>
      <el-space wrap :size="10" class="mt-1">
        <el-button type="primary" plain>批量刪除</el-button>
        <el-button type="primary" plain>增加</el-button>
      </el-space>
    </div>
    <el-table
      ref="multipleTableRef"
      :data="tableData"
      style="width: 100%"
      @selection-change="handleSelectionChange"
    >
      <el-table-column type="selection" width="55" />
      <el-table-column prop="m_id" label="ID" />
      <el-table-column prop="material_name" label="素材名稱" />
      <el-table-column prop="create_time" label="創建時間" />
      <el-table-column label="操作" width="200">
        <template #default="scope">
          <el-button
            link
            size="small"
            type="primary"
            @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            link
            size="small"
            type="danger"
            @click="handleEdit(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <div class="mt-2 flex justify-center">
      <el-pagination
        v-model:current-page="params.current_page"
        v-model:page-size="params.page_size"
        :page-sizes="[10, 20, 30, 40]"
        :small="false"
        :disabled="false"
        :background="true"
        layout="total, sizes, prev, pager, next"
        :total="Number(total)"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </div>
  </el-card>
</template>
<script lang="ts" setup>
import { ref, onMounted, toRefs } from "vue";
import { Search, Goods } from "@element-plus/icons-vue";
import { $msgList } from "@api/setting";
import { dayjs } from "element-plus";
import { useRoute } from "vue-router";
const route = useRoute();
const multipleTableRef = ref<InstanceType<typeof ElTable>>();
const multipleSelection = ref([]);
let params = ref({
  current_page: 1,
  page_size: 10,
  material_name: "",
  material_type:"text",
});
const total = ref(0);
const tableData = ref([]);
if(route.query.material_type){
params.value.material_type=route.query.material_type
}
onMounted(() => {
  getData();
});
const getData = async () => {
  let res = await $msgList(params.value);
  if (res.code == 0) {
    tableData.value = res.data.table;
    total.value = res.data.total;
  }
};
const handleSizeChange = (val: number) => {
  params.value.page_size = val;
  getData();
};
const handleCurrentChange = (val: number) => {
  params.value.current_page = val;
  getData();
  console.log(`current page: ${val}`);
};
const handleSelectionChange = (val: array) => {
  console.log(val);
  multipleSelection.value = val;
};
const disabledDateFun = (date) => {
  let now = dayjs().subtract(1, "day");
  if (date < now) return false;
  return true;
};
const search = () => {
  console.log(params.value);
  getData();
};
const handleClick = () => {
  getData();
};
</script>

<style lang="scss" scoped></style>
